package com.dhsc.service.impl.xtqxgl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.ywzx.xtqxgl.LsqxglVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.xtqxgl.ILsqxglDao;
import com.dhsc.service.xtqxgl.ILsqxglService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: LsqxglServiceImpl
 * @Description: 临时权限管理
 * @date: 2023/11/23 11:22
 * @author: gx
 */
@Service
@Slf4j
public class LsqxglServiceImpl implements ILsqxglService {

    @Autowired
    private ILsqxglDao lsqxglDao;

    @Override
    public LayuiTableVo queryLsqxgl(LsqxglVo lsqxglVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(lsqxglVo.getPage(), lsqxglVo.getLimit());
            List<LsqxglVo> list = lsqxglDao.queryLsqxgl(lsqxglVo);
            PageInfo<LsqxglVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询临时权限管理出错",e);
            throw new MyException("查询临时权限管理出错");
        }
        return obj;
    }

    @Override
    public ResponseObject saveLsqxgl(LsqxglVo lsqxglVo) {
        ResponseObject obj = new ResponseObject();
        try {
            lsqxglDao.insertLsqxgl(lsqxglVo);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("保存临时权限管理出错",e);
            throw new MyException("保存临时权限管理出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject deleteLsqxgl(LsqxglVo lsqxglVo) {
        ResponseObject obj = new ResponseObject();
        try {
            lsqxglDao.deleteLsqxgl(lsqxglVo);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("删除临时权限管理出错",e);
            throw new MyException("删除临时权限管理出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYhmc(LsqxglVo lsqxglVo) {
        ResponseObject obj = new ResponseObject();
        try {
            List<LsqxglVo> list = lsqxglDao.queryYhmc(lsqxglVo);
            obj.setData(list);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("查询用户名称出错",e);
            throw new MyException("查询用户名称出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryJsxz(LsqxglVo lsqxglVo) {
        ResponseObject obj = new ResponseObject();
        try {
            List<LsqxglVo> list = lsqxglDao.queryJsxz(lsqxglVo);
            obj.setData(list);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("查询角色信息出错", e);
            throw new MyException("查询角色信息出错",e);
        }
        return obj;
    }
}
